```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LRU算法深度解析 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
            background-color: #f8f9fa;
        }
        .serif {
            font-family: 'Noto Serif SC', serif;
        }
        .hero-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .code-block {
            font-family: 'Courier New', Courier, monospace;
            background-color: #2d3748;
            color: #e2e8f0;
            border-radius: 0.5rem;
            overflow-x: auto;
        }
        .code-keyword {
            color: #f6ad55;
        }
        .code-type {
            color: #68d391;
        }
        .code-string {
            color: #f687b3;
        }
        .code-comment {
            color: #a0aec0;
        }
        .code-method {
            color: #63b3ed;
        }
        .drop-cap:first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            font-weight: bold;
            color: #4c51bf;
        }
        .mermaid-container {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-bg text-white py-20 px-4 md:py-28">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col items-center text-center">
                <span class="bg-white bg-opacity-20 px-4 py-1 rounded-full text-sm font-semibold mb-4">算法解析</span>
                <h1 class="serif text-4xl md:text-5xl font-bold leading-tight mb-6">LRU缓存淘汰算法</h1>
                <p class="text-xl max-w-2xl opacity-90 mb-8">Least Recently Used — 高效缓存管理的核心策略</p>
                <div class="flex space-x-4">
                    <a href="#intro" class="bg-white text-indigo-700 px-6 py-3 rounded-full font-medium hover:bg-opacity-90 transition-all">
                        <i class="fas fa-book-open mr-2"></i>开始阅读
                    </a>
                    <a href="#implementation" class="border border-white border-opacity-30 text-white px-6 py-3 rounded-full font-medium hover:bg-white hover:bg-opacity-10 transition-all">
                        <i class="fas fa-code mr-2"></i>查看实现
                    </a>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Intro Section -->
        <section id="intro" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-indigo-500 w-12 rounded-full"></div>
                <h2 class="serif text-3xl font-bold ml-4">算法简介</h2>
            </div>
            <div class="drop-cap bg-white rounded-xl shadow-md p-8 mb-8">
                <p class="text-lg mb-6">LRU（Least Recently Used）算法是一种用于缓存管理的淘汰策略，用于在缓存满时决定哪些缓存项应该被移除。LRU算法的核心思想是移除最久未被访问的数据，从而保留最近使用的数据。这种策略能够在很多应用场景中提升缓存的有效性，比如内存缓存、磁盘缓存等。</p>
                <p class="text-lg mb-6">LRU算法的基本原则是"最近使用的数据保留，最久未使用的数据淘汰"。要实现这个原则，需要维护两个主要的信息：数据访问顺序和缓存空间。在缓存满时，需要根据访问顺序来决定移除哪个数据项。</p>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="text-indigo-500 text-3xl mb-4">
                        <i class="fas fa-project-diagram"></i>
                    </div>
                    <h3 class="serif text-xl font-bold mb-3">数据结构</h3>
                    <p class="text-gray-600">为了高效实现LRU算法，通常结合使用双向链表和哈希表。双向链表记录访问顺序，哈希表提供快速查找能力，共同实现O(1)时间复杂度操作。</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="text-indigo-500 text-3xl mb-4">
                        <i class="fas fa-tachometer-alt"></i>
                    </div>
                    <h3 class="serif text-xl font-bold mb-3">性能优势</h3>
                    <p class="text-gray-600">LRU算法在缓存命中率高的情况下表现优异，能有效减少缓存未命中带来的性能开销。特别适合访问模式具有局部性的场景。</p>
                </div>
            </div>
        </section>

        <!-- Data Structure Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-indigo-500 w-12 rounded-full"></div>
                <h2 class="serif text-3xl font-bold ml-4">数据结构选择</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                <div class="p-8">
                    <p class="text-lg mb-6">为了高效地实现LRU算法，常用的两种数据结构是<strong>双向链表（Doubly Linked List）</strong>和<strong>哈希表（Hash Map）</strong>。它们结合使用可以在O(1)的时间复杂度内完成基本操作，包括访问、插入和删除。</p>
                    
                    <div class="grid md:grid-cols-2 gap-8 mt-6">
                        <div>
                            <h3 class="serif text-xl font-bold mb-4 text-indigo-600">
                                <i class="fas fa-link mr-2"></i>双向链表
                            </h3>
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-indigo-500 mt-1">
                                        <i class="fas fa-check-circle"></i>
                                    </div>
                                    <p class="ml-2">用于记录缓存项的访问顺序</p>
                                </li>
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-indigo-500 mt-1">
                                        <i class="fas fa-check-circle"></i>
                                    </div>
                                    <p class="ml-2">链表的头部表示最近访问的缓存项</p>
                                </li>
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-indigo-500 mt-1">
                                        <i class="fas fa-check-circle"></i>
                                    </div>
                                    <p class="ml-2">尾部表示最久未访问的缓存项</p>
                                </li>
                            </ul>
                        </div>
                        <div>
                            <h3 class="serif text-xl font-bold mb-4 text-indigo-600">
                                <i class="fas fa-table mr-2"></i>哈希表
                            </h3>
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-indigo-500 mt-1">
                                        <i class="fas fa-check-circle"></i>
                                    </div>
                                    <p class="ml-2">用于快速查找缓存项的位置</p>
                                </li>
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-indigo-500 mt-1">
                                        <i class="fas fa-check-circle"></i>
                                    </div>
                                    <p class="ml-2">键是缓存项的标识符</p>
                                </li>
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-indigo-500 mt-1">
                                        <i class="fas fa-check-circle"></i>
                                    </div>
                                    <p class="ml-2">值是链表节点的引用</p>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                
                <div class="bg-gray-50 p-8 border-t border-gray-200">
                    <h3 class="serif text-xl font-bold mb-4">LRU数据结构可视化</h3>
                    <div class="mermaid-container">
                        <div class="mermaid">
                            graph LR
                                subgraph 哈希表
                                    A[Key1] --> B[Node1]
                                    C[Key2] --> D[Node2]
                                    E[Key3] --> F[Node3]
                                end
                                subgraph 双向链表
                                    B <--> D <--> F
                                end
                                style 哈希表 fill:#f5f7ff,stroke:#6366f1
                                style 双向链表 fill:#f0fdf4,stroke:#10b981
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Operation Flow Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-indigo-500 w-12 rounded-full"></div>
                <h2 class="serif text-3xl font-bold ml-4">操作流程</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="text-indigo-500 text-2xl mb-3 bg-indigo-50 rounded-full w-12 h-12 flex items-center justify-center">
                        1
                    </div>
                    <h3 class="serif text-xl font-bold mb-3">访问操作</h3>
                    <p class="text-gray-600">当访问一个缓存项时，首先在哈希表中查找该项。如果找到，更新其在双向链表中的位置，将其移动到链表头部（表示最近访问）。如果找不到，则需要从数据源加载数据。</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="text-indigo-500 text-2xl mb-3 bg-indigo-50 rounded-full w-12 h-12 flex items-center justify-center">
                        2
                    </div>
                    <h3 class="serif text-xl font-bold mb-3">插入操作</h3>
                    <p class="text-gray-600">当插入新的缓存项时，如果缓存未满，直接将新项添加到链表头部。如果缓存已满，则需要移除链表尾部的缓存项（最久未使用的项），然后将新项添加到链表头部。</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="text-indigo-500 text-2xl mb-3 bg-indigo-50 rounded-full w-12 h-12 flex items-center justify-center">
                        3
                    </div>
                    <h3 class="serif text-xl font-bold mb-3">删除操作</h3>
                    <p class="text-gray-600">当删除缓存项时，首先在哈希表中找到该项，然后从链表中移除对应的节点，最后从哈希表中删除该项的记录。</p>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md p-8">
                <h3 class="serif text-xl font-bold mb-4">LRU操作流程图</h3>
                <div class="mermaid-container">
                    <div class="mermaid">
                        flowchart TD
                            A[访问缓存] --> B{存在哈希表中?}
                            B -->|是| C[移动节点到链表头部]
                            B -->|否| D[从数据源加载数据]
                            D --> E{缓存已满?}
                            E -->|是| F[移除链表尾部节点]
                            E -->|否| G[插入新节点到链表头部]
                            F --> G
                            C --> H[返回缓存数据]
                            G --> H
                    </div>
                </div>
            </div>
        </section>

        <!-- Code Implementation Section -->
        <section id="implementation" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-indigo-500 w-12 rounded-full"></div>
                <h2 class="serif text-3xl font-bold ml-4">代码实现</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-6 border-b border-gray-200 bg-gray-50 flex justify-between items-center">
                    <div class="flex items-center">
                        <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-green-500"></div>
                    </div>
                    <span class="text-sm text-gray-500">LRUCache.java</span>
                </div>
                <div class="p-8">
                    <div class="code-block p-6 rounded-lg mb-6">
                        <pre><code><span class="code-keyword">import</span> java.util.LinkedHashMap;
<span class="code-keyword">import</span> java.util.Map;

<span class="code-keyword">public class</span> <span class="code-type">LRUCache</span>&lt;<span class="code-type">K</span>, <span class="code-type">V</span>&gt; <span class="code-keyword">extends</span> <span class="code-type">LinkedHashMap</span>&lt;<span class="code-type">K</span>, <span class="code-type">V</span>&gt; {
    <span class="code-keyword">private final</span> <span class="code-type">int</span> capacity;

    <span class="code-keyword">public</span> <span class="code-type">LRUCache</span>(<span class="code-type">int</span> capacity) {
        <span class="code-comment">// true for accessOrder to maintain access order</span>
        <span class="code-keyword">super</span>(capacity, <span class="code-number">0.75f</span>, <span class="code-keyword">true</span>);
        <span class="code-keyword">this</span>.capacity = capacity;
    }

    <span class="code-keyword">@Override</span>
    <span class="code-keyword">protected</span> <span class="code-type">boolean</span> <span class="code-method">removeEldestEntry</span>(<span class="code-type">Map</span>.<span class="code-type">Entry</span>&lt;<span class="code-type">K</span>, <span class="code-type">V</span>&gt; eldest) {
        <span class="code-keyword">return</span> <span class="code-method">size</span>() > capacity;
    }

    <span class="code-keyword">public</span> <span class="code-keyword">static</span> <span class="code-type">void</span> <span class="code-method">main</span>(<span class="code-type">String</span>[] args) {
        <span class="code-type">LRUCache</span>&lt;<span class="code-type">Integer</span>, <span class="code-type">String</span>&gt; lruCache = <span class="code-keyword">new</span> <span class="code-type">LRUCache</span>&lt;&gt;(<span class="code-number">3</span>);

        lruCache.<span class="code-method">put</span>(<span class="code-number">1</span>, <span class="code-string">"A"</span>);
        lruCache.<span class="code-method">put</span>(<span class="code-number">2</span>, <span class="code-string">"B"</span>);
        lruCache.<span class="code-method">put</span>(<span class="code-number">3</span>, <span class="code-string">"C"</span>);
        <span class="code-type">System</span>.<span class="code-keyword">out</span>.<span class="code-method">println</span>(lruCache); <span class="code-comment">// Output: {1=A, 2=B, 3=C}</span>

        lruCache.<span class="code-method">get</span>(<span class="code-number">1</span>); <span class="code-comment">// Access key 1</span>
        lruCache.<span class="code-method">put</span>(<span class="code-number">4</span>, <span class="code-string">"D"</span>); <span class="code-comment">// Insert new key 4, which causes key 2 to be evicted</span>
        <span class="code-type">System</span>.<span class="code-keyword">out</span>.<span class="code-method">println</span>(lruCache); <span class="code-comment">// Output: {1=A, 3=C, 4=D}</span>
    }
}</code></pre>
                    </div>
                    
                    <div class="grid md:grid-cols-2 gap-8">
                        <div class="bg-blue-50 rounded-lg p-6">
                            <h3 class="serif text-xl font-bold mb-4 text-blue-600">
                                <i class="fas fa-lightbulb mr-2"></i>实现要点
                            </h3>
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-blue-500 mt-1">
                                        <i class="fas fa-check"></i>
                                    </div>
                                    <p class="ml-2">继承<code class="bg-blue-100 text-blue-800 px-1 rounded">LinkedHashMap</code>类，利用其访问顺序特性</p>
                                </li>
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-blue-500 mt-1">
                                        <i class="fas fa-check"></i>
                                    </div>
                                    <p class="ml-2">构造函数中设置<code class="bg-blue-100 text-blue-800 px-1 rounded">accessOrder</code>为<code class="bg-blue-100 text-blue-800 px-1 rounded">true</code>以维护访问顺序</p>
                                </li>
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-blue-500 mt-1">
                                        <i class="fas fa-check"></i>
                                    </div>
                                    <p class="ml-2">重写<code class="bg-blue-100 text-blue-800 px-1 rounded">removeEldestEntry</code>方法实现自动淘汰</p>
                                </li>
                            </ul>
                        </div>
                        <div class="bg-purple-50 rounded-lg p-6">
                            <h3 class="serif text-xl font-bold mb-4 text-purple-600">
                                <i class="fas fa-cogs mr-2"></i>复杂度分析
                            </h3>
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-purple-500 mt-1">
                                        <i class="fas fa-bolt"></i>
                                    </div>
                                    <p class="ml-2"><strong>访问:</strong> O(1)，通过哈希表查找并移动节点到链表头部</p>
                                </li>
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-purple-500 mt-1">
                                        <i class="fas fa-bolt"></i>
                                    </div>
                                    <p class="ml-2"><strong>插入:</strong> O(1)，在链表头部插入新节点</p>
                                </li>
                                <li class="flex items-start">
                                    <div class="flex-shrink-0 h-6 w-6 text-purple-500 mt-1">
                                        <i class="fas fa-bolt"></i>
                                    </div>
                                    <p class="ml-2"><strong>删除:</strong> O(1)，从链表中删除节点并更新哈希表</p>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Pros & Cons Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-indigo-500 w-12 rounded-full"></div>
                <h2 class="serif text-3xl font-bold ml-4">优缺点分析</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="bg-green-500 text-white px-6 py-4">
                        <h3 class="serif text-xl font-bold flex items-center">
                            <i class="fas fa-thumbs-up mr-3"></i>优点
                        </h3>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-4">
                            <li class="flex">
                                <div class="flex-shrink-0 h-6 w-6 text-green-500 mt-1">
                                    <i class="fas fa-check-circle"></i>
                                </div>
                                <div class="ml-3">
                                    <h4 class="font-bold text-lg">高效性</h4>
                                    <p class="text-gray-600">结合哈希表和双向链表可以在O(1)时间内完成基本操作</p>
                                </div>
                            </li>
                            <li class="flex">
                                <div class="flex-shrink-0 h-6 w-6 text-green-500 mt-1">
                                    <i class="fas fa-check-circle"></i>
                                </div>
                                <div class="ml-3">
                                    <h4 class="font-bold text-lg">适用性广</h4>
                                    <p class="text-gray-600">适用于需要管理缓存的场景，如内存缓存和磁盘缓存</p>
                                </div>
                            </li>
                            <li class="flex">
                                <div class="flex-shrink-0 h-6 w-6 text-green-500 mt-1">
                                    <i class="fas fa-check-circle"></i>
                                </div>
                                <div class="ml-3">
                                    <h4 class="font-bold text-lg">性能稳定</h4>
                                    <p class="text-gray-600">在缓存命中率高的情况下表现优异</p>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="bg-red-500 text-white px-6 py-4">
                        <h3 class="serif text-xl font-bold flex items-center">
                            <i class="fas fa-thumbs-down mr-3"></i>缺点
                        </h3>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-4">
                            <li class="flex">
                                <div class="flex-shrink-0 h-6 w-6 text-red-500 mt-1">
                                    <i class="fas fa-exclamation-circle"></i>
                                </div>
                                <div class="ml-3">
                                    <h4 class="font-bold text-lg">内存开销</h4>
                                    <p class="text-gray-600">需要额外的内存来维护双向链表和哈希表的结构</p>
                                </div>
                            </li>
                            <li class="flex">
                                <div class="flex-shrink-0 h-6 w-6 text-red-500 mt-1">
                                    <i class="fas fa-exclamation-circle"></i>
                                </div>
                                <div class="ml-3">
                                    <h4 class="font-bold text-lg">实现复杂</h4>
                                    <p class="text-gray-600">相对于简单的缓存实现，LRU缓存的实现复杂度较高</p>
                                </div>
                            </li>
                            <li class="flex">
                                <div class="flex-shrink-0 h-6 w-6 text-red-500 mt-1">
                                    <i class="fas fa-exclamation-circle"></i>
                                </div>
                                <div class="ml-3">
                                    <h4 class="font-bold text-lg">锁竞争</h4>
                                    <p class="text-gray-600">在多线程环境下需要额外的同步机制</p>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-400 py-12">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col items-center">
                <div class="text-xl font-bold text-white mb-2">技术小馆</div>
                <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition-colors">
                    <i class="fas fa-external-link-alt mr-2"></i>http://www.yuque.com/jtostring
                </a>
                <div class="mt-6">
                    <a href="#" class="text-gray-400 hover:text-white mx-3">
                        <i class="fab fa-github text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white mx-3">
                        <i class="fab fa-twitter text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white mx-3">
                        <i class="fab fa-linkedin text-xl"></i>
                    </a>
                </div>
                <div class="mt-6 text-sm">
                    &copy; 2023 技术小馆. 保留所有权利.
                </div>
            </div>
        </div>
    </footer>

    <!-- Mermaid JS -->
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```